'''
* This is the projet for Brtc LlmOps Platform
* @Author Leon-liao <liaosiliang@alltman.com>
* @Description //TODO 
* @File: study_dict.py
* @Time: 2025/6/22
* @All Rights Reserve By Brtc
'''
# 数据类型之字典的操作
# 字典的定义
# 能过够根据 key 寻找到 value
# 如何定义一个字典
# 定义一个空字典
"""
empty_dict = {}
print(f"type dict = {type(empty_dict)}")

# 数据是怎么 存储的 {key:value, key:value} key 可以是  任意 类型   value 也可以是任意 类型
person_dict = {"name":"吴彦祖", "age":18, "car":"红色", "money": 1.88}

print(f"我的名字叫{person_dict["name"]}")  # value 是 str
print(f"今年{person_dict["age"]}岁！")# value  是  number
print(f"我有{person_dict["money"]}亿！")# value 是  浮点数
print(f"我还有一辆{person_dict["car"]}色的车！")# value 是 str

#key 可以是  任意 类型   value 也可以是任意 类

# 定义了一个自己构造的 数据类型Peson
class Peson:
    name:str = ""
    age:int  = ""
    money:float = 0
    def __init__(self,name,age,money):
        self.name = name
        self.age = age
        self.money = money

    def introduce(self):
        print(f"我的名字叫{self.name}, 今年{self.age}岁, 拥有{self.money}个亿")


test_dict = {9527:Peson("吴彦祖", 18, 2.88)} # 将 number  作为  字典的key    将person 作为字典的 数据类型
one_person = test_dict[9527]#  通过  数字  去获取 数字 对应的person
one_person.introduce()

"""

"""
person_dict = {"name":"吴彦祖", "age":18, "car":"红色", "money": 1.88}
#  如何对 字典里面 key- value 进行遍历
for key, value in person_dict.items():
    print(f"key = {key}  value = {value}")

print("=====================================================================")
# 字典增加数据
person_dict["婚姻"] = "已婚"
for key, value in person_dict.items():
    print(f"key = {key}  value = {value}")

# 查询某个key 有没有在 字典里面
print("name" in person_dict)


# 修该某一个数据
person_dict["age"] = 60
print("=====================================================================")
for key, value in person_dict.items():
    print(f"key = {key}  value = {value}")

# 数据的 删除
del person_dict["婚姻"]
print("=====================================================================")

for key, value in person_dict.items():
    print(f"key = {key}  value = {value}")
"""
# 字典的嵌套
dict_car = {"brand":"法拉利", "price":"400w"}
dict_one = {"name":"吴彦祖", "age":18, "car":dict_car, "money": 1.88}
print(dict_one)
